package pers.chao.logger.enums;

/**
 * Description: 彩色日志主题方案
 *
 * @author W.Chao
 * @date 2020/11/21 19:26
 **/
public enum ColorfulLogTheme {
	DEFAULT("no-color-default", "%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level --- %logger{50}: %msg%n"),
	LITE("no-color-lite", "%d{yyyy-MM-dd HH:mm:ss} [%logger{50}] --- %-5level - %msg%n"),
	MORE("no-color-more", "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level --- [%logger{50}].[%method] --- %msg%n"),
	COLORFUL_DEFAULT("colorful-default", "%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) --- [%thread] %cyan(%logger{50}): %green(%msg%n)"),
	COLORFUL_LITE("colorful-lite", "%d{yyyy-MM-dd HH:mm:ss} %cyan([%logger{50}]) --- %highlight(%-5level) - %msg%n"),
	COLORFUL_MORE("colorful-more", "\"%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) --- [%logger{50}].[%method] --- %cyan(%msg%n)"),
	COLOR_BLOCK("color-block", "%red(%date{yyyy-MM-dd HH:mm:ss}) %highlight(%-5level) %red([%thread]) %boldMagenta(%logger{50}) %cyan(%msg%n)"),
	FRESH("fresh", "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){green} %clr(%-5p){red} %clr(---){blue} %clr([%30.30t]){yellow} %clr(%-40.40logger{39}){cyan} %clr(:){blue} %msg%n"),
	LINE("line", "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){green} | %clr(%-5p){red} %clr(---){blue} | %clr([%30.30t]){yellow} | %clr(%-40.40logger{39}){cyan} | %clr(:){blue} | %msg%n"),
	COLORFUL_DEFAULT_SIMPLE("colorful-simple", "「MsG」%d{yyyy-MM-dd HH:mm:ss.SSS} | %highlight(%-5level) --- [%thread] %cyan(%logger{50}) | %msg%n"),
	NO_MORE("no-more", "「MsG」%d{yyyy-MM-dd HH:mm:ss.SSS} | %cyan(%logger{50}) | %msg%n");

	private String theme;
	private String pattern;

	ColorfulLogTheme(String theme, String pattern) {
		this.theme = theme;
		this.pattern = pattern;
	}

	public String getTheme() {
		return theme;
	}

	public String getPattern() {
		return pattern;
	}

	/**
	 * 通过主题名获取对应的格式
	 *
	 * @param theme
	 * @return
	 */
	public static String of(String theme) {
		ColorfulLogTheme[] values = values();
		for (ColorfulLogTheme value : values) {
			if (value.getTheme().equals(theme)) {
				return value.getPattern();
			}
		}
		return DEFAULT.getPattern();
	}

	/**
	 * 解析，非内置主题格式则判断为用户自定义
	 *
	 * @param patternOrTheme
	 * @return
	 */
	public static String resolvePattern(String patternOrTheme) {
		ColorfulLogTheme[] values = values();
		for (ColorfulLogTheme value : values) {
			if (value.getTheme().equals(patternOrTheme)) {
				return value.getPattern();
			}
		}
		return patternOrTheme;
	}
}
